package com.sp.scmdb.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sp.scmdb.bean.UploadDutyBean;
import com.sp.scmdb.common.action.BaseAction;
import com.sp.scmdb.entity.Duty;
import com.sp.scmdb.webservice.service.UploadDutyService;

@Controller("uploadDutyAction")
@Scope("prototype")
public class UploadDutyAction extends BaseAction<UploadDutyBean> {

	private static final long serialVersionUID = 1L;
	private static Log log = LogFactory.getLog(UploadDutyAction.class);
	
	private UploadDutyService dutyService;

	@Autowired
	public void setUploadDutyService(UploadDutyService dutyService) {
		this.dutyService = dutyService;
	}
	
	/**
	 * 职务上传页面初始化
	 */
	public String init(){
		try {
			entity.setListDutyLevel(dutyService.queryDutyLevelList());
		} catch (Exception e) {
			log.error("init fail!reason:" + e.getMessage());
		}
		
		return "init";
	}
	
	/**
	 * 职务列表查询
	 */
	public String findAll() {		
		try{
			entity.setListDutyLevel(dutyService.queryDutyLevelList());
			List<Duty> depList = dutyService.queryAll(entity);
			entity.setAllList(depList);
			entity.setAllList(depList);
			entity.setList(depList.subList(entity.getCurrentRow(), entity.getLastRow()));
			
		} catch(RuntimeException e){			
			log.error("findAll fail!reason:" + e.getMessage());
			return "fail";
		} catch(Exception e){
			log.error("findAll fail!reason:" + e.getMessage());
			return "error";
		}
		return SUCCESS;
	}
}
